const path = require('path')

const resolve = dir => path.resolve(dir)
// console.log(process.env)
module.exports = {
  publicPath: ".",//修改资源目录的路径
  lintOnSave: false,
  //代理原理 使用了一个中间件 叫做 http-proxy-middleware
  devServer: {
    proxy: {
      "/api": {
        target: process.env.VUE_APP_BASE_URL, //目标服务器
        pathRewrite: {//路径重写
          "^/api": ""
        }
      },
      "/cart": {
        target: process.env.VUE_APP_CART_URL,
        pathRewrite: {
          "^/cart": ""
        }
      }
    }
  },
  //配置别名
  chainWebpack: (config) => {
    config.resolve.alias
      .set('$', resolve('src'))
      .set('assets', resolve('src/assets'))
      .set('components', resolve('src/components'))
      .set('layout', resolve('src/layout'))
      .set('base', resolve('src/base'))
      .set('static', resolve('src/static'))
  }
};

//真实服务器地址:https://chst.vip/data/index.json
//代理之后的地址其实是:https://chst.vip/api/data/index.json
